package com.old.people.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.old.people.entities.Account;
import com.old.people.entities.OldPeople;
import com.old.people.entities.Servicer;
import com.old.people.service.LogginServices;
import com.old.people.util.ShortChainUtils;

@RestController
public class LogginController {
	@Autowired
	private LogginServices logginServices;

	@RequestMapping("consumer/userloggin")
	@ResponseBody
	public String userLoggin(@RequestParam("oldpeople_name") String oldpeople_name,@RequestParam("oldpeople_sex") String oldpeople_sex,
	@RequestParam("oldpeople_idcard") String oldpeople_idcard,@RequestParam("oldpeople_address") String oldpeople_address,
	@RequestParam("oldpeople_tel") String oldpeople_tel, @RequestParam("oldpeople_description") String oldpeople_description, 
	@RequestParam("oldpeople_familytel") String oldpeople_familytel,@RequestParam("account_password") String account_password) {
		String temp = ShortChainUtils.getString();
		String account_id=ShortChainUtils.getString();
		boolean flag=logginServices.userLoggin(temp, oldpeople_name, oldpeople_sex, oldpeople_idcard, oldpeople_address, 
				oldpeople_tel, oldpeople_description, oldpeople_familytel, account_id, account_password, temp, "4");
		if(flag==true) {
			return account_id;
		}
		return "false";

	}

	@RequestMapping("consumer/servicerloggin")
	@ResponseBody
	public String servicerLoggin(@RequestParam("servicer_name") String servicer_name,@RequestParam("servicer_sex") String servicer_sex,
			@RequestParam("servicer_tel") String servicer_tel,@RequestParam("servicer_idcard") String servicer_idcard,
			@RequestParam("account_password") String account_password) {
		String temp = ShortChainUtils.getString();
		String account_id=ShortChainUtils.getString();
		boolean flag=logginServices.servicerLoggin(temp, servicer_name, servicer_sex, servicer_tel, servicer_idcard, "", account_id, account_password, temp, "5");
		if(flag==true) {
			return account_id;
		}
		return "false";
	}

	@RequestMapping("consumer/managerloggin")
	@ResponseBody
	public String managerLoggin(@RequestParam("account_password") String account_password) {
		String account_id=ShortChainUtils.getString();
		boolean flag=logginServices.managerLoggin(account_id, account_password, "", "6");
		if(flag==true) {
			return account_id;
		}
		return "false";
	}
}
